﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;

namespace IFRS.DataAccess.DAL
{
    public class SPR_SUBSUDYLOAN
    {
        public DataTable SearchAll(SubsidyLoan subsidyloan, Paging paging, bool isAllBranch, string sCostCenter, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));

                lstParams.Add(new SqlParameter("@isAllBranch", isAllBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@sCostCenter", sCostCenter.AsDBValue()));

                lstParams.Add(new SqlParameter("@TransactionDate", subsidyloan.TransactionDate));
                lstParams.Add(new SqlParameter("@AccountNo", subsidyloan.AccountNo));
                lstParams.Add(new SqlParameter("@CostCenter", subsidyloan.CostCenter));
                lstParams.Add(new SqlParameter("@IsConfirmed", subsidyloan.IsConfirmed));
                dt = Utility.StoredProcDataTable("SPR_SUBSIDYLOAN_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int SubsidyLoanID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@SubsidyLoanID", SubsidyLoanID));
                dt = Utility.StoredProcDataTable("SPR_SUBSIDYLOAN_SEARCHBYID", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(SubsidyLoan subsidyloan)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@SubsidyLoanID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@TransactionDate", subsidyloan.TransactionDate));
                lstParams.Add(new SqlParameter("@AccountNo", subsidyloan.AccountNo));
                lstParams.Add(new SqlParameter("@CostCenter", subsidyloan.CostCenter));
                lstParams.Add(new SqlParameter("@GLAccount", subsidyloan.GLAccount));
                lstParams.Add(new SqlParameter("@CurrencyCode", subsidyloan.CurrencyCode));
                lstParams.Add(new SqlParameter("@ReferenceInterestCD", subsidyloan.ReferenceInterestCD));
                lstParams.Add(new SqlParameter("@AdditionalInterest", subsidyloan.AdditionalInterest));
                lstParams.Add(new SqlParameter("@IsCompensate", subsidyloan.IsCompensate));
                lstParams.Add(new SqlParameter("@IsConfirmed", subsidyloan.IsConfirmed));
                //lstParams.Add(new SqlParameter("@RP_GSB_PRDCD", subsidyloan.RP_GSB_PRDCD));
                //lstParams.Add(new SqlParameter("@RP_SOURCE_FILE", subsidyloan.RP_SOURCE_FILE));
                //lstParams.Add(new SqlParameter("@RP_MAPPING_CD", subsidyloan.RP_MAPPING_CD));
                lstParams.Add(new SqlParameter("@CreatedDate", subsidyloan.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", subsidyloan.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", subsidyloan.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", subsidyloan.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", subsidyloan.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", subsidyloan.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", subsidyloan.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", subsidyloan.UpdatedBranch));

                Utility.ExecuteStoredProc("SPR_SUBSIDYLOAN_INSERT", lstParams.ToArray());
                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(SubsidyLoan subsidyloan)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@SubsidyLoanID", subsidyloan.SubsidyLoanID));
                lstParams.Add(new SqlParameter("@TransactionDate", subsidyloan.TransactionDate));
                lstParams.Add(new SqlParameter("@AccountNo", subsidyloan.AccountNo));
                lstParams.Add(new SqlParameter("@CostCenter", subsidyloan.CostCenter));
                lstParams.Add(new SqlParameter("@GLAccount", subsidyloan.GLAccount));
                lstParams.Add(new SqlParameter("@CurrencyCode", subsidyloan.CurrencyCode));
                lstParams.Add(new SqlParameter("@ReferenceInterestCD", subsidyloan.ReferenceInterestCD));
                lstParams.Add(new SqlParameter("@AdditionalInterest", subsidyloan.AdditionalInterest));
                lstParams.Add(new SqlParameter("@IsCompensate", subsidyloan.IsCompensate));
                lstParams.Add(new SqlParameter("@IsConfirmed", subsidyloan.IsConfirmed));
                lstParams.Add(new SqlParameter("@UpdatedDate", subsidyloan.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", subsidyloan.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", subsidyloan.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", subsidyloan.UpdatedBranch));

                iNum = (int)Utility.ExecuteStoredProc("SPR_SUBSIDYLOAN_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(SubsidyLoan subsidyloan)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@SubsidyLoanID", subsidyloan.SubsidyLoanID));
                lstParams.Add(new SqlParameter("@UpdatedDate", subsidyloan.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", subsidyloan.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", subsidyloan.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", subsidyloan.UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_SUBSIDYLOAN_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

    }
}
